/*
 * @Author: 李兵 964368540@qq.com
 * @Date: 2024-05-25 13:40:08
 * @LastEditors: libing 9852442+liu-sheng-8667@user.noreply.gitee.com
 * @LastEditTime: 2024-05-26 23:08:28
 * @FilePath: \crm\pages\mixins\async-select.js
 * @Description: 客户类型  异步下拉
 */
import { getCustomerTypes, getCustomerLevels } from "@/apis/customer";
import { setCustomerType,setCustomerLevel } from '@/config/storage'
const asyncSelectMixins = {
  data() {
    return {
      customerTypesObj: {},
      customerLevelsObj: {}
    };
  },
  mounted() {
    this.customerTypes = this._getCustomerTypes()
    this.customerLevels = this._getCustomerLevels()
  },
  methods: {
    // 获取客户类型
    async _getCustomerTypes() {
      const data = await getCustomerTypes();
      const records = data?.records || [];
      setCustomerType(records)
      this.customerTypesObj = this.getObj(records)
      return records

    },
    // 获取客户等级
    async _getCustomerLevels() {
      const data = await getCustomerLevels();
      const records = data?.records || [];
      setCustomerLevel(records)
      this.customerLevelsObj = this.getObj(records)
      return records
    },
    // 获取key   value
    getObj(data) {
      const obj = {}
      data.forEach(i=>{
        obj[i.id] = i.name
      })
      return obj
    }
  },
};

export default asyncSelectMixins;
